﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;

public partial class UserManagement_UpdateWebUserInfo : UserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack) 
        {
            ShowUserInfo();
        }
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
       
        if (this.txtVU_Password.Text.Trim() != null && this.txtagainpwd.Text.Trim() == null)
        {
            this.labManage.Text = "请再次填写密码";
        }
        if (this.txtVU_Password.Text.Trim() == this.txtagainpwd.Text.Trim())
        {
            string userId = Request.QueryString["ID"];
            V_user user = new V_user();
            UserModule um = new UserModule();
            user.SchoolID = CurrentUser.SchoolID;
            user.ID = Convert.ToInt32(Request.QueryString["ID"].ToString());
            user.update_time = DateTime.Now;
            user.VU_email = txtVU_email.Text.Trim();
            user.VU_loginname = txtVU_loginname.Text.Trim();
            user.VU_mobile = txtVU_mobile.Text.Trim();
            if (txtVU_Password.Text.Trim() != null)
            {
                user.VU_Password = txtVU_Password.Text.Trim();
            }
            user.VU_realname = txtVU_realname.Text.Trim();
            try
            {
                int i = um.UpdateUser(user);
                Session["currentUser"] = user;
                if (i > 0)
                {
                    PageHelper.AlterMsg("修改个人信息成功！");
                    //Response.Redirect("../UserPersonalCenter/UserCourseCalendar.aspx?SchoolId="+this.SchoolID);
                }
                else { PageHelper.AlterMsg("修改个人信息失败"); }
            }
            catch (Exception ex)
            {
                PageHelper.AlterMsg("修改个人信息失败");
            }
        }
        else
        {

            PageHelper.AlterMsg("两次输入的密码不一致");
        }
       
    }

    private void ShowUserInfo()
    {
        UserModule um = new UserModule();
        int UID = Convert.ToInt32(Request.QueryString["ID"].ToString());
        V_user user = new V_user();
        user = um.GetUserModelById(UID);
        txtVU_email.Text = user.VU_email;
        txtVU_loginname.Text = user.VU_loginname;
        txtVU_mobile.Text = user.VU_mobile;
        txtVU_realname.Text = user.VU_realname;
    }

    //清空session，退出登陆
    protected void lbtnzhuxiao_Click(object sender, EventArgs e)
    {
        string schoolId = this.SchoolID.ToString();
        Session.Clear();
        Session.Abandon();
        Response.Redirect("../ev" + schoolId + "/index.ev", true);
       
    }
}
